<?php
namespace Backend\Controller;
use Think\Controller;

class  AdsenseController extends  BaseController
{
    public  function  index(){

        $model =D('Adsense');
        $data=$model ->get_adsense();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));

        $this->display('index');
    }


    public  function  create(){

        $data=$_POST;
        if($data)
        {
            $model = D('Adsense');
            if (!$data = $model->create()) {
                $this->ajaxReturn(['status' => 'failed', 'msg' => $model->getError()]);
                exit;
            }else{

                if($result = $model->add())
                {

                    $this->ajaxReturn(['status' => 'success', 'msg' => '添加成功！']);
                    exit;
                }else{
                    $this->ajaxReturn(['status' => 'failed', 'msg' =>$model->getError() ]);
                    exit;
                }
            }
        }
        $result =D('Apply')->field('id,apply_name')->order('id desc')->select();
        $this->assign('result',$result);
        $this->display();
    }

    public  function  delete(){
        if(!$_POST['id']){
            $this->ajaxReturn(['status' => 'failed', 'msg' => '操作有误，重新选择！']);
            die;

        }
        $where ='id in('.trim($_POST['id'],',').')';
        $model = D('Adsense');
        $res =$model->where($where)->delete();
        //echo $model->getLastSql();exit;
        if ($res) {
            $this->ajaxReturn(['status' => 'success', 'msg' => '操作成功！']);
        } else {
            $this->ajaxReturn(['status' => 'failed', 'msg' => '操作失败！']);
        }
    }

}